package com.wangyadong.hobby.test.test1;

import sun.nio.ch.ThreadPool;

import java.util.DoubleSummaryStatistics;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Java8Collector {


    public static void main(String[] args) {
        summingDouleTest();
        partitionByeTest();
    }

    public static void partitionByeTest() {
        Map<Boolean, List<Production>> collect = Stream.of(new Production("wyd", 123.9d)
                , new Production("wzx", 103.6d)
                , new Production("wyd", 113.5d)
                , new Production("wzx", 93.4d))
                .collect(Collectors.partitioningBy(p -> p.price > 105d));
        System.out.println(collect);
    }

    public static void summingDouleTest() {
        DoubleSummaryStatistics collect = Stream.of(new Production("wyd", 123.9d)
                , new Production("gff", 103.6d)
                , new Production("syp", 113.5d)
                , new Production("wzx", 93.4d))
                .collect(Collectors.summarizingDouble(Production::getPrice));
        double sum = collect.getSum();
        System.out.println(sum);
    }

    private static class Production {
        private final String name;
        private final double price;

        public Production(String name, double price) {
            this.name = name;
            this.price = price;
        }

        public String getName() {
            return name;
        }

        public double getPrice() {
            return price;
        }
    }
}
